Fix: Resolve Thymeleaf 3.1.4+ TemplateProcessingException in variables.css (Issue #5251)#5264
Fix: Resolve Thymeleaf 3.1.4+ TemplateProcessingException in variables.css (Issue #5251)#5264EIHEI2 wants to merge 1 commit intocodecentric:masterfrom
Conversation
…estriction - Add cssColors model attribute to UiController with pre-computed RGB values - Update variables.css template to use cssColors instead of @cssColorUtils bean reference - Add SpringStandardDialect bean configuration for compatibility This fixes the TemplateProcessingException caused by Thymeleaf 3.1.4.RELEASE which forbids bean references (@cssColorUtils) in CSS templates.
| @ModelAttribute(value = "cssColors", binding = false) | ||
| public Map<String, String> getCssColors() { | ||
| var palette = uiSettings.getTheme().getPalette(); | ||
| return Map.of( |
There was a problem hiding this comment.
Given that the values here come from the configuration, I would personally just compute this map once in the constructor when the controller is created and just reuse that value every time the endpoint gets called.
That's just a small optimisation :)
There was a problem hiding this comment.
As the properties may be changed at runtime (via Spring Boot Admin's Properties UI + Spring Cloud mechanisms), i tend to have it in a method instead of a constructor.
There was a problem hiding this comment.
Ah ok. I was not aware of this possibility.
Makes sense then.
| public UiController(String publicUrl, UiExtensions uiExtensions, Settings uiSettings) { | ||
| private final CssColorUtils cssColorUtils; | ||
|
|
||
| public UiController(String publicUrl, UiExtensions uiExtensions, Settings uiSettings, CssColorUtils cssColorUtils) { |
There was a problem hiding this comment.
Since you have extended/changed the controller constructor, check all parts where this is used. I guess that at least the tests are broken.
There was a problem hiding this comment.
Error: Failed to execute goal io.spring.javaformat:spring-javaformat-maven-plugin:0.0.47:validate (default) on project spring-boot-admin-server-ui: Formatting violations found in the following files:
Error: * /home/runner/work/spring-boot-admin/spring-boot-admin/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java
There was a problem hiding this comment.
I try to build this PR locally ... compile error:
./mvnw clean install -DskipTests -Dspring-javaformat.skip=true
INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/Dev/git/privat/spring-boot-admin/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java:[135,24] constructor UiController in class de.codecentric.boot.admin.server.ui.web.UiController cannot be applied to given types;
required: java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings,de.codecentric.boot.admin.server.ui.config.CssColorUtils
found: java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings
reason: actual and formal argument lists differ in length
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Spring Boot Admin 4.1.0-SNAPSHOT:
[INFO]
[INFO] Spring Boot Admin .................................. SUCCESS [ 4.128 s]
[INFO] Spring Boot Admin Dependencies ..................... SUCCESS [ 0.292 s]
[INFO] Spring Boot Admin Build ............................ SUCCESS [ 0.453 s]
[INFO] Spring Boot Admin Server ........................... SUCCESS [01:18 min]
[INFO] Spring Boot Admin Server UI ........................ FAILURE [02:41 min]
[INFO] Spring Boot Admin Client ........................... SKIPPED
[INFO] Spring Boot Admin Docs ............................. SKIPPED
[INFO] Spring Boot Admin Server Cloud ..................... SKIPPED
[INFO] Spring Boot Admin Server Starter ................... SKIPPED
[INFO] Spring Boot Admin Client Starter ................... SKIPPED
[INFO] Spring Boot Admin Samples .......................... SKIPPED
[INFO] Spring Boot Admin Server custom UI ................. SKIPPED
[INFO] Spring Boot Admin Sample Servlet ................... SKIPPED
[INFO] Spring Boot Admin Sample Reactive .................. SKIPPED
[INFO] Spring Boot Admin Sample War ....................... SKIPPED
[INFO] Spring Boot Admin Sample Hazelcast ................. SKIPPED
[INFO] Spring Boot Admin Sample Eureka .................... SKIPPED
[INFO] Spring Boot Admin Sample Consul .................... SKIPPED
[INFO] Spring Boot Admin Sample Zookeeper ................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:05 min
[INFO] Finished at: 2026-04-20T11:08:36+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) on project spring-boot-admin-server-ui: Compilation failure
[ERROR] /D:/Dev/git/privat/spring-boot-admin/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java:[135,24] constructor UiController in class de.codecentric.boot.admin.server.ui.web.UiController cannot be applied to given types;
[ERROR] required: java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings,de.codecentric.boot.admin.server.ui.config.CssColorUtils
[ERROR] found: java.lang.String,de.codecentric.boot.admin.server.ui.extensions.UiExtensions,de.codecentric.boot.admin.server.ui.web.UiController.Settings
[ERROR] reason: actual and formal argument lists differ in length
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :spring-boot-admin-server-ui
AD001+hoehmann@dinmPF5F7PQ0 • 2026-04-20 • 11:08 • MINGW64 /d/Dev/git/privat/spring-boot-admin (fix-issue-47) •
There was a problem hiding this comment.
Indeed the expectations from @SteKoe were correct then.
There was a problem hiding this comment.
@ahoehma the bean is already registered in the context.
Therefore, for the sake of testing, you can just add it as parameter in https://github.com/codecentric/spring-boot-admin/blob/master/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java#L100 and then pass that parameter to https://github.com/codecentric/spring-boot-admin/blob/master/spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java#L127.
Moreover, I would suggest you to run it with -Dmaven.test.skip=true instead of -DskipTests so that Maven doesn't even try to compile the tests (which maybe would fail as well).
There was a problem hiding this comment.
I fixed the few compile errors by myself ... now I try to include the 4.1.0-SNAPSHOT into my project ... keep you informed asap :-)
There was a problem hiding this comment.
Hmmm ... I'm using the snapshot now ... build is fine ... startup also fine .. but then when I try to open sba ...
2026-04-20 12:42:12 [ http-nio-9090-exec-9] ERROR - [] - org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]:170 - Servlet.service() for servlet [dispatcherServlet] threw exception
org.thymeleaf.exceptions.ConfigurationException: Conflicting execution attribute. Two or more dialects specify an execution attribute with the same name "StandardExpressionParser".
at org.thymeleaf.DialectSetConfiguration.build(DialectSetConfiguration.java:268)
at org.thymeleaf.EngineConfiguration.<init>(EngineConfiguration.java:123)
at org.thymeleaf.TemplateEngine.initialize(TemplateEngine.java:341)
at org.thymeleaf.TemplateEngine.getConfiguration(TemplateEngine.java:411)
at org.thymeleaf.spring6.view.ThymeleafView.renderFragment(ThymeleafView.java:265)
at org.thymeleaf.spring6.view.ThymeleafView.render(ThymeleafView.java:193)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1305)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1042)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:866)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1000)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:892)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:874)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:710)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:128)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:107)
There was a problem hiding this comment.
Can you please try removing the spring standard dialect bean which was added in the PR?
I suspect there is already one coming from Spring Boot itself, therefore now Thymeleaf doesn't know which one to use.
There was a problem hiding this comment.
Yep. Now its up and running - CSS issues gone! 👍
Branch: fix/5251 ./mvnw clean install -DskipTests -Dspring-javaformat.skip=true -Dcheckstyle.skip=true Green ... and inside my app the CSS still fixed 👍 |
Thanks for checking it, @ahoehma. |
|
Hey there, thanks for your hard work! That's much appreciated! I will close this PR as it is superseeded by the new PR created by you, @cdprete. |
Description
This PR fixes the TemplateProcessingException that occurs with Thymeleaf 3.1.4.RELEASE when processing the variables.css template.
Problem
Thymeleaf 3.1.4+ introduced stricter security restrictions that forbid bean references (@cssColorUtils) in CSS templates, causing the following error:
Solution
Changes
Testing
The fix avoids bean references in the template while maintaining the same functionality. The RGB values are computed once per request in the controller instead of per-variable in the template.
Fixes #5251